<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>欢迎页面-X-admin2.2</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>

</head>
<body>
	<div class="layui-form" >

		<div class="layui-form-item">
			<div class="layui-inline">
				<div class="layui-input-inline">
					<button class="layui-btn layui-btn-sm" onclick="oncs()"
						style="margin-top: 10px; margin-left: 50px">
						<i class="layui-icon layui-icon-addition">添加书籍</i>
					</button>
				</div>
			</div>

			<div class="layui-inline">
				<label class="layui-form-label" style="margin-top: 10px">请输入书名：</label>
				<div class="layui-input-inline">
					<input type="tel" name="bookName" id="bookName" autocomplete="off"
						class="layui-input" style="margin-top: 13px">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label" style="margin-top: 10px">请输入出版社：</label>
				<div class="layui-input-inline">
					<input type="tel" name="bookPress" id="bookPress" autocomplete="off"
						class="layui-input" style="margin-top: 13px">
				</div>
			</div>

			<button class="layui-btn" id="search"  style="margin-top: 5px"
				data-type="reload">查询</button>

		</div>

	</div>

	<script type="text/html" id="barDemo">
 		 <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit">编辑</i> </a>
 		 <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>

	<script type="text/html" id="statictmp">
    <input type="checkbox" name="onoff" value="{{d.sid}}"   lay-skin="switch" lay-text="在线|离线" lay-filter="switchtest" {{d.statuses=='true' ?'checked':'在线'}}>
    </script>

	<table class="layui-hide" id="test" lay-filter="demo"></table>
	<script>
		layui.use([ 'table', 'form', 'layer' ], function() {
			var table = layui.table;
			var form = layui.form;
			var layer = layui.layer;
			var $ = layui.jquery;
			table.render({
				elem : '#test',
				url : '/selectBook',
				method: 'POST', //请求的方式
				cols : [ [ {
					field : 'bookid',
					title : 'ID',
					sort : true
				}, {
					field : 'bookName',
					title : '书名字'
				}, {
					field : 'bookPress',
					title : '出版社',
				}, {
					field : 'bIntroduction',
					title : '图书简介'
				}, {
					field : 'bookStock',
					title : '库存'
				}, {
					field : 'rRnum',
					title : '所属阅览室id'
				}, {
					fixed : 'right',
					align : 'center',
					toolbar : '#barDemo'
				} ] ],
				id : 'testReload',//写了一个Id，目的是一会从新加载表格用的
				page : true
			});

			
			//监听工具条
			table.on('tool(demo)', function(obj) {
				var data = obj.data;
				var $ = layui.jquery;
				if (obj.event === 'detail') {
					//查看
				} else if (obj.event === 'del') {
					layer.confirm('真的删除行么', function(index) {
						console.log(obj.data);
						$.post('/deleteBook', {
							bookid : obj.data.bookid

						}, function(data) {
							layer.close(index);
							window.location.reload();
							//当窗口关闭之后刷新页面
						}, "json");
					});
				} else if (obj.event === 'edit') {
					console.log(obj.data);
					layer.open({ //打开一个页面
						type : 2, //在当前的页面之上，弹框形式，展示出添加用户的界面
						area : [ '450px', '550px' ], //页面的宽高
						content : 'book-edit.html', //页面所在的位置
						title : '编辑书籍信息',
						success : function(layero, index) {
							var body = layer.getChildFrame('body', index);
							//val(obj.data.p_bannerid);   括号里面是数据回显代码
							body.contents().find("#bookid").val(obj.data.bookid);
							body.contents().find("#bookName").val(obj.data.bookName);
							body.contents().find("#bookPress").val(obj.data.bookPress);
							body.contents().find("#bIntroduction").val(
									obj.data.bIntroduction);
							body.contents().find("#bookStock").val(obj.data.bookStock);
							body.contents().find("#rRnum").val(obj.data.rRnum);
						},
						end : function() {
							window.location.reload();//当窗口关闭之后刷新页面
						}
					});
				}
				
				
				
				
				
			

			});
		

			/* 下拉框 */
			form.on('select(xiala)', function(data) {
				if (data.value == 1) {
					console.log(data.value);
					form.render('select');
				} else {
					console.log(data.value);
					form.render('select');//刷新select选择框渲染
				}
			});
			
			
			//给search一个点击事件
			//当我执行点击的收走这个方法 search是button的id
			$('#search').on('click', function() {
				var bookName = $("#bookName").val();//上面搜索框的id
				var bookPress = $("#bookPress").val();//上面搜索框的id
				table.reload('testReload', {//testReload,是上面渲染表格的id
					where : {//接口需要的两个请求参数
						'bookName' : bookName,
						'bookPress' : bookPress
					}
				});

			});

		});
		
		function oncs() {
			layer.open({
				type : 2,
				area : [ '450px', '550px' ], //页面的宽高
				content : 'book-add.html',
				title : '添加学生',
				success : function(layero, index) {

				},
				end : function() {
					window.location.reload();
				}
			})
		}
		
		
	
	</script>
	


</body>

</html>